<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/StoresSystem' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/StoresSystem/ShopsList' }">门店列表</el-breadcrumb-item>
      <el-breadcrumb-item >商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="bians">
    <el-input placeholder="请输入查询内容" v-model="search.searchValue" class="input-with-select">
      <el-select v-model="search.searchType" slot="prepend" placeholder="请选择">
        <el-option label="商品名字" value="name"></el-option>
        <el-option label="商品价格" value="price"></el-option>
        <el-option label="商品数量" value="num"></el-option>
      </el-select>
      <el-button slot="append" icon="el-icon-search" @click="serchGoods"></el-button>
    </el-input>
     </div>
    <el-table
      size="small"
      :data="pageData.rows"
      style="width: 100%"
    >
      <el-table-column label="商品编号" prop="_id" width="190%"></el-table-column>
      <el-table-column label="商品名字" prop="name"></el-table-column>
      <el-table-column label="商品价格" prop="price"></el-table-column>
      <el-table-column label="商品数量" prop="num"></el-table-column>
      <el-table-column label="商品门店" prop="shopsId.name"></el-table-column>
        <el-table-column label="商品图片" >
          <template slot-scope="scope" >
            <img class="studentsImage" :src="scope.row.images"/>
          </template>
        </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="centerDialogVisible = true">修改</el-button>
          <!-- <template v-if="true"></template> -->
          <el-dialog title="修改信息" :visible.sync="centerDialogVisible" >
            <el-form >
              <el-form-item label="商品名字：">
                <el-input  autocomplete="off" v-model="scope.row.name">{{scope.row.name}}</el-input>
              </el-form-item>
              <el-form-item label="商品价格：">
                <el-input  autocomplete="off" v-model="scope.row.price"></el-input>
              </el-form-item>
              <el-form-item label="商品数量：">
                <el-input  autocomplete="off" v-model="scope.row.num"></el-input>
              </el-form-item>
              <el-form-item label="商品门店：">
                <el-select v-model="scope.row.shopsId.name" placeholder="请选择商品门店">
                    <el-option label="门店一" :value="scope.row._id">
                    </el-option>
                  <!-- <el-option v-for="item in classes" :label="item.name" :value="item._id" :key="item._id"></el-option> -->
                </el-select>
              </el-form-item>
              
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="centerDialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="updata(scope.row)" :plain="true">确 定</el-button>
            </div>
          </el-dialog>

          <el-button
            size="mini"
            type="danger"
            
            @click="removeGoods(scope.row)"
            :plain="true"
          >下架</el-button>
        </template>
      </el-table-column>
    </el-table>      
    <div class="block">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageData.currentPage"
        :page-sizes="[1,2,3,4]"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { createNamespacedHelpers } from "vuex";
const {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("stores");

export default {
  data() {
    return {
      search: {
        searchType: "",
        searchValue: ""
      },
      centerDialogVisible: false,
    };
  },
  computed: {
    ...mapState(["pageData"]),
  },
  created() {
    this.getGoodsCellAsync();
    // console.log(this.pageData);
  },
  methods: {
    ...mapMutations(["changepageSize","changePage"]),
    // ...mapMutations(["updateStudents", "close"]),
    ...mapActions([
      "getGoodsCellAsync" , "deleteGoodsCellAsync" , "updataGoodsCellAsync"
    ]),
    //下架
    removeGoods(row){
      this.deleteGoodsCellAsync(row._id);
      this.$message({
          showClose: true,
          message: '下架成功',
          type: 'success'
        });
      
      this.getGoodsCellAsync();
      
    },
    //分页
    handleCurrentChange(val) {
      this.changePage(val);
       this.getGoodsCellAsync();
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.changepageSize(val);
       this.getGoodsCellAsync();
    },
    // 点击修改改变数据
    updata(row){
      this.updataGoodsCellAsync(row);
      //  this.getGoodsCellAsync();
      this.$message({
          showClose: true,
          message: '修改成功',
          type: 'success'
        });
      this.centerDialogVisible =false;
    },
    //
    serchGoods(){
      console.log();
      //  this.getStudentsAsync()
      this.getGoodsCellAsync(this.search);
    }
  }
};
</script>

<style>
.el-breadcrumb {
  padding-left: 10px;
  height: 30px;
}


.el-table__header-wrapper .has-gutter tr th {
  line-height: 60px;
}
.has-gutter .cell {
  text-align: center;
  font-size: 14px;
}
.el-table__row .cell {
  text-align: center;
}
.is-right button {
  margin-right: 5px;
}
.el-dialog {
  width: 440px;
}
.el-form-item {
  padding: 0 40px;
}
.el-dialog__header {
  display: flex;
}
.el-dialog .el-input {
  width: 260px;
}
.el-dialog__close {
  display: none;
}
.dialog-footer {
  padding-right: 40px;
}

.el-pagination {
  margin-top: 10px;
  height: 30px !important;
}
.studentsImage {
  width: 50px;
}
.el-select .el-input {
    width: 130px;
  }
  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }
  .bans{
    line-height: 60px;
  }
</style>